package com.stu.spring04.mapper;

import com.stu.spring04.entity.User;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: UserMapperImpl
 * Package: com.stu.spring04.mapper
 * Description: @Version 1.0
 */
@Repository("userMapper")
public class UserMapperImpl implements IUserMapper{
    List<User> userList=new ArrayList<>();

    public UserMapperImpl() {
        User user1=new User(1,"张一","111","小一",null,null);
        User user2=new User(2,"张二","222","小二",null,null);
        User user3=new User(3,"张三","333","小三",null,null);
        this.userList.add(user1);
        this.userList.add(user2);
        this.userList.add(user3);
    }

    @Override
    public Integer addUser(User user) {
        user.setId(11);
        System.out.println(user);
        return 1;
    }

    @Override
    public List<User> selectUser() {
        return userList;
    }

    @Override
    public User selectUserById(int id) {
        for (User eve:userList ) {
            if(eve.getId()==id){
                return eve;
            }
        }
        return null;
    }
}
